package com.changfeng.handler;


import com.changfeng.exception.ChangFengException;
import com.changfeng.handler.response.vo.ResponseVO;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ControllerAdvice
public class GlobalExceptionHandler {

    private final Log logger = LogFactory.getLog(this.getClass());

    @ExceptionHandler({ChangFengException.class})
    @ResponseBody
    public ResponseVO changFengExceptionHandler(ChangFengException e, HttpServletRequest request, HttpServletResponse response) {
        e.printStackTrace();
        return ResponseVO.forException(e);
    }
    /**
     * 其他时异常
     * @param e        异常请求
     * @param request  请求信息
     * @param response 响应信息
     * @return 封装后的响应异常信息
     */

    @ExceptionHandler({Exception.class})
    @ResponseBody
    public ResponseVO exceptionHandler(Exception e, HttpServletRequest request, HttpServletResponse response) {
        e.printStackTrace();
        return ResponseVO.appFail();
    }




}
